/*	BuildValkyrie class definition.
 *
*/

#include "BuildValkyrie.h"

void BuildValkyrie::Enter()
{
	DEBUG_PRINT("BuildValkyrie(%p) %s entering\n", this, GetName().c_str());

}

void BuildValkyrie::Execute()
{
	DEBUG_PRINT("BuildValkyrie(%p) %s executing\n", this, GetName().c_str());
	std::list<Base*>* bases = BB->GetBases();
	std::list<BWAPI::Unit*>* starList;
	BWAPI::Unit* star = NULL;
	for(std::list<Base*>::iterator base = bases->begin(); base != bases->end(); base++)
	{
		starList = (*base)->GetBuildingsByType(BWAPI::UnitTypes::Terran_Starport);
		if(starList)
		{
			for(std::list<BWAPI::Unit*>::iterator it = starList->begin(); it != starList->end(); it++)
			{
				if (!(*it)->isTraining() && !(*it)->isBeingConstructed())
					star = *it;
			}
			if (star) 
			{
				BB->SpendResources(BWAPI::UnitTypes::Terran_Valkyrie);
				star->train(BWAPI::UnitTypes::Terran_Valkyrie);
			}
		}
	}
	control->FinishWithSuccess();
}

void BuildValkyrie::Exit()
{
	DEBUG_PRINT("BuildValkyrie(%p) %s exiting\n", this, GetName().c_str());

}

bool BuildValkyrie::CheckConditions()
{
	DEBUG_PRINT("BuildValkyrie(%p) %s checking conditions\n", this, GetName().c_str());
	if(BB->isBuildUnit(BWAPI::UnitTypes::Terran_Valkyrie) )
	{
		DEBUG_PRINT("BuildValkyrie(%p) %s checked conditions and has %d minerals to spend\n", this, GetName().c_str(), BB->GetMineralsToSpend());
		
		return true;
	}
	return false;
}